home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1997 December
/
MACPOWER-1997-12.ISO.7z
/
MACPOWER-1997-12.ISO
/
MacPowerオリジナル
/
キョービのプログラマー
/
Flash Trash src
/
ShowInitIcon.c
< prev
Wrap
C/C++ Source or Header
|
1997-09-06
|
3KB
|
117 lines
#include <Gestalt.h>
#include <Icons.h>
#include <OSUtils.h>
#ifndef CurApName
#define CurApName 0x0910
#endif
extern short my_h : CurApName+32-4;
extern short my_check : CurApName+32-2;
#ifndef NULL
#define NULL ( (void *)0 )
#endif
#define ICON_HEIGHT 32
#define ICON_WIDTH 32
#define FIRST_X 8
#define BOTTOM_MARGIN 8
#define DEF_MOVE_X_BY 40
#define CHECKSUM_CONST 0x1021
#define MIN_BIT_DEPTH 4
OSErr ShowInitIcon( short icon_num, short move_x_by);
void plot_icn(Rect *r, Handle icn_handle);
OSErr ShowInitIcon( short icon_num, short move_x_by)
{
// short err;
Handle icon_h=NULL; /* handle to 'ICN#' or 'cicn' resource */
Boolean in_color=FALSE; /* TRUE='cicn' resource, else 'ICN#' */
GrafPtr oldport;
GrafPort newport; /* Entire GrafPort structure */
Rect r; /* where to put the icon */
// SysEnvRec sys_rec;
short screen_width;
long resp;
if( (Gestalt(gestaltQuickdrawFeatures, &resp) == noErr) && (resp & (31 - gestaltHasColor)) ) {
// if ( (err = SysEnvirons(1, &sys_rec)) != 0 )
// return(err);
// if ( sys_rec.hasColorQD ) /* a Mac II or later... */
// {
GDHandle gdev = GetGDevice(); /* get main screen */
if ( (*(*gdev)->gdPMap)->pixelSize >= MIN_BIT_DEPTH )
icon_h = (Handle)GetCIcon(icon_num);
if ( icon_h != NULL )
in_color = TRUE;
}
if ( icon_h == NULL ) /* no icon yet, try a B&W one */
icon_h = Get1Resource('ICN#', icon_num);
if ( icon_h == NULL )
return(resNotFound); /* we're SOL here */
HNoPurge( icon_h );
GetPort(&oldport); /* save old GrafPort for later restoring */
OpenPort(&newport);
SetPort(&newport);
if ( ((my_h <<1) ^ CHECKSUM_CONST) != my_check )
my_h = FIRST_X;
screen_width = newport.portRect.right - newport.portRect.left;
screen_width -= screen_width % DEF_MOVE_X_BY; /* in case screen isn't multiple of 40 */
r.left = my_h % screen_width;
r.right = r.left + ICON_WIDTH;
r.top = newport.portRect.bottom - ((BOTTOM_MARGIN+ICON_HEIGHT) * (1 + my_h / screen_width));
r.bottom = r.top + ICON_HEIGHT;
if ( in_color )
PlotCIcon(&r, (CIconHandle)icon_h); /* Toolbox's plot routine */
else
plot_icn(&r, icon_h); /* our routine */
if ( move_x_by == -1 )
move_x_by = DEF_MOVE_X_BY;
my_h += move_x_by;
my_check = (my_h<<1) ^ CHECKSUM_CONST;
if ( in_color )
DisposeCIcon((CIconHandle)icon_h);
else
ReleaseResource(icon_h);
SetPort(oldport);
ClosePort(&newport);
return(0);
}
void plot_icn(r, icn_handle)
Rect *r;
Handle icn_handle;
{
BitMap bm;
char flags;
GrafPtr cur_port;
flags = HGetState(icn_handle);
HLock(icn_handle);
GetPort(&cur_port);
bm.baseAddr = *icn_handle + ICON_WIDTH*ICON_HEIGHT/8; /* points to mask */
bm.rowBytes = ICON_WIDTH / 8; /* ICON_WIDTH/8 must be power of 2 */
SetRect(&bm.bounds, 0, 0, ICON_WIDTH, ICON_HEIGHT);
/* punch a hole in the Desktop using bit-clear mode and the mask */
CopyBits(&bm, &cur_port->portBits, &bm.bounds, r, srcBic, NULL);
/* now copy the icon into the punched hole */
bm.baseAddr = *icn_handle; /* points to ICON */
CopyBits(&bm, &cur_port->portBits, &bm.bounds, r, srcOr, NULL);
HSetState(icn_handle, flags);
}